package com.itany;

import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.ZooKeeper;

import java.io.IOException;

/**
 * Author：汤小洋
 * Date：2019-12-13 15:06
 * Description：<描述>
 */
public class HelloZooKeeper {
    public static void main(String[] args) throws IOException, KeeperException, InterruptedException {
        /**
         * 获取ZooKeeper连接
         */
        ZooKeeper zooKeeper = new ZooKeeper("127.0.0.1:2181", 3000, new MyWatcher());

        // System.out.println(zooKeeper);
        // System.out.println("-----------------"+zooKeeper.getSessionId());


        // 查看
        // List<String> children = zooKeeper.getChildren("/", false);// 相当于 ls /  watch
        // System.out.println(children);

        // 创建
        // zooKeeper.create("/welcome","789".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

        // 修改
        // zooKeeper.setData("/welcome","666".getBytes(),-1); // -1表示不检测版本

        // 删除
        // zooKeeper.delete("/welcome",-1);

        System.out.println(zooKeeper.exists("/hello",false));
    }
}
